package pit.com.ordermobilesystem.http;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;

import org.apache.http.impl.client.DefaultHttpClient;


public class HttpApiWithAuth extends BaseHttpApi {
  private static final String authKey = "mobiplace.net_";

  public HttpApiWithAuth() {
    super();
  }

  public HttpApiWithAuth(DefaultHttpClient httpClient) {
    super(httpClient);
  }

  @Override
  public HttpURLConnection createHttpURLConnection(URL url) throws IOException {
    HttpURLConnection conn = super.createHttpURLConnection(url);
    Encryption encry = new Encryption();
    conn.setRequestProperty("HASH", encry.encode(authKey + new Date().getTime()));
    return conn;
  }

  @Override
  public HttpModel doHttpRequest(String url, Parser<? extends HttpModel> parser, ResponseType type)
      throws HttpApiException, IOException {
    return executeHttpRequest(url, parser, type);
  }

  @Override
  public HttpModel doHttpRequest(String url, String content, Parser<? extends HttpModel> parser,
      ResponseType type) throws HttpApiException, IOException {
    return executeHttpRequestContent(url, content, parser, type);
  }
}
